<?php $id = getId(); ?>
<form action="<?php _baseUrl()?>/crm/Act/delete" method="post" id="f<?php _e($id);?>">
<div class="x-list-title">
	<table width="100%" border="0" height="100%">
	<tr>
	<td align="left">
		<h2>
			Danh sách công ty
		</h2>
	</td>
	<td align="right">	
		<div class="x-list-options">
			<?php _e( tpl_search_form(baseUrl()."/Crm/Customer/Search", "#Crm/Customer/Search") );?>
						
			<div class="x-options-container">
				<a class="x-button">Tạo mới  <span class="x-tri">&#9660;</span></a> 
				<div class="x-options">
					<a class="x-options-item" href="#Crm/Customer/Add">Công ty</a>
					<a class="x-options-item" href="#Crm/Contact/Add">Liên hệ</a>
					<a class="x-options-item" href="#Crm/Opportunity/Add">Cơ hội</a>
					<a class="x-options-item" href="#Crm/Contract/Add">Hợp đồng</a>
				</div>
			</div>

			<div class="x-options-container">
				<a class="x-button">Nhóm KH  <span class="x-tri">&#9660;</span></a> 
				<div class="x-options">
					<?php foreach( $this->get('cats') as $k => $a ):?>
					<a class="x-options-item" href="#Crm/Customer?parent_id=<?php _e($a['ID']);?>"><?php _e($a['title']);?></a>
					<?php endforeach;?>
				</div>
			</div>
			
			<div class="x-options-container">
				<a class="x-button">Giao dịch  <span class="x-tri">&#9660;</span></a> 
				<div class="x-options">
					<?php 
						$vars = $this->get('vars');
						$rlink = rawurlencode('Crm/Customer?'.to_query_configs($vars));
					?>
					<a class="x-options-item" onclick="Owl('#f<?php _e($id);?>').each(function(){ var s =[] ; $(this).find('.x-checkbox:checked').each(function(){  s.push('customer_id[]='+this.value); });  if(s.length == 0){ $.Alert('Hãy chọn công ty') }else{ load_inframe('<?php _baseUrl()?>/Crm/Transaction/Add?redirect=<?php _e($rlink)?>&'+ s.join('&'),{ title: 'Thêm giao dịch'} ) }   })">Thêm giao dịch</a>
					<a class="x-options-item" onmousedown="Owl('#f<?php _e($id);?>').each(function(){ var s =[] ; $(this).find('.x-checkbox:checked').each(function(){  s.push( $(this).next('textarea').get('value')) });  if(s.length == 0){ $.Alert('Hãy chọn công ty') }else{ location.href='mailto:'+ s.join(', ') }   })">Gửi email</a>					
					<a class="x-options-item" onclick="Owl('#f<?php _e($id);?>').each(function(){ var s =[] ; $(this).find('.x-checkbox:checked').each(function(){  s.push('customer_id[]='+this.value); });  if(s.length == 0){ $.Alert('Hãy chọn công ty') }else{ load_inframe('<?php _baseUrl()?>/Crm/Transaction/Sms?redirect=<?php _e($rlink)?>&'+ s.join('&'),{ title: 'Giao dịch SMS'} ) }   })">Gửi SMS</a>
				</div>
			</div>
			<div class="x-options-container">
				<a class="x-button">Tác vụ khác  <span class="x-tri">&#9660;</span></a> 
				<div class="x-options">
					<a onclick="module_delete('<?php _baseUrl();?>/Crm/Customer/Delete','f<?php _e($id);?>',this)"  class="x-options-item x-track">Xóa đã chọn</a>
					<a class="x-options-item" onclick="load_inframe('<?php _baseUrl();?>/Crm/Customer/Changecare',{title: 'Đổi người chăm sóc', dataForm: 'form#f<?php _e($id);?>'})">Đổi người chăm sóc</a>	
					<a class="x-options-item" onclick="load_inframe('<?php _ctrUrl($this);?>/Export',{ title:'Xuất file', height:'300px',dataForm: 'form#f<?php _e($id);?>' })">Xuất ra Exel </a>					
				</div>
			</div>
		</div>
	</td>
	</tr>
	</table>	
</div>

		<?php $vars = $this->get('vars');?>
		<table width="100%" cellpadding="0" cellspacing="0" class="x-list" >
			<tr>
				<th width="25" align="center">TT</th>
				<th width="70">
					<?php show_order_link('Mã','code','#Crm/Customer',$vars) ;?>
				</th>
				<th>
					<?php show_order_link('Tên công ty','name','#Crm/Customer',$vars) ;?>
				</th>
				<th width="150">
					<?php show_order_link('Website','website','#Crm/Customer',$vars) ;?>
				</th>
				<th width="110">
					<?php show_order_link('Phone','phone','#Crm/Customer',$vars) ;?>
				</th>
				<th width="150">
					<?php show_order_link('Email','email','#Crm/Customer',$vars) ;?>
				</th>
				<th width="80">
					<?php show_order_link('Chăm sóc','care_by_id','#Crm/Customer',$vars) ;?>
				</th>
				
				<th width="25" colspan="2">Tác vụ</th>
				
				<th align="center" width="25">
					<div class="x-check-container">
						<div class="x-check">
						<input type="checkbox" class="x-checkall"/>
						</div>
						<div class="x-check-options">
							<a class="x-check-item check-all">Chọn tất cả</a>
							<a class="x-check-item uncheck-all">Bỏ chọn tất cả</a>
						</div>
					</div>
				</th>
			</tr>
			<?php if( count($this->get('posts')) == 0):?>
			<tr>
			<td class='page' colspan='10'>
				<div class='x-page'>Chưa có bản ghi nào được tạo</div>
			</td></tr>
			<?php else:?>
			<?php foreach( $this->get('posts') as $k => $a ):?>
				<tr>
					<td align="center">
						<?php _e($k+1);?>
					</td>
					<td align="center">
						<?php _e($a['code']);?>
					</td>
					<td>
						<a href="#Crm/Customer/View?ID=<?php _e($a['ID']);?>"><?php _e($a['name']);?></a>
					</td>
					<td>
						<?php _e(show_url($a['website'],28));?>
					</td>
					<td align="center">
						<?php _e($a['phone']);?>
					</td>
					
					<td>
						<?php _e(show_email($a['name'],$a['email'],25));?>
					</td>

					<td align="center">
						<?php _e(get_user_link($a['care_by_id'],$a['care_by_name'],$a['care_is_deleted']));?>
					</td>

					
					<td width="25" align="center">
						<?php if(  $a['created_by_id'] == get_user_id() || $this->hasRole('crm_admin') || $a['care_by_id'] == get_user_id()  ){?>
						<a href="#Crm/Customer/Edit?ID=<?php _e($a['ID']);?>" class="x-edit"></a>
						<?php }else{?>
						<a class="x-noedit"></a>
						<?php }?>
					</td>
					<td width="25" align="center">
						<?php 
							unset($vars['p']);
							$url = 'Crm/Customer'.( count($vars) > 0 ? '?'.to_query_configs($vars,true) : '');
							$url = rawurlencode($url);
						?>
						<?php if(  $a['created_by_id'] == get_user_id() || $this->hasRole('crm_admin') ){?>
						<a onclick="module_delete('<?php _baseUrl()?>/Crm/Customer/Delete?ID[]=<?php _e($a['ID']);?>&url=<?php _e($url)?>')" class="x-delete"></a>
						<?php }else{?>
						<a class="x-nodelete"></a>
						<?php }?>
					</td>
					<td align="center">
						<?php _e(tpl_checkbox_item($a['ID']));?>
						<textarea style='display:none'><?php _e($a['name']);?> <<?php _e($a['email']);?>></textarea>
					</td>
				</tr>
			<?php endforeach;?>
				<tr>
					<td colspan="10" class="page">
						<div class="x-page">
							<?php $this->e('page');?>
						</div>		
					</td>
				</tr>
			<?php endif;?>
			
		</table>
	</form>
